﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using RAE.Logica.Info;
using RAE.Logica.Torneos;
using RAE.Logica.Controladores;

namespace RAE.GUI.Torneos
{
    public partial class PanelRegistroPartidas : Page
    {
        private VentanaRegistroTorneos ventana;
        private Torneo torneo;
        
        public PanelRegistroPartidas(VentanaRegistroTorneos v)
        {
            InitializeComponent();
            ventana = v;
        }

        public void configurar(Torneo t)
        {
            torneo = t;
            torneo.crosstable = new List<FilaCrosstable>();
            
            DataGridTextColumn columna;
            
            for (int i=0; i<torneo.cantidad_rondas; i++) {
                columna = new DataGridTextColumn();
                columna.Header = "Ronda " + (i+1);
                columna.Binding = new Binding("resultados[" + i + "]");
                columna.IsReadOnly = false;
                grid_crosstable.Columns.Add(columna);
            }

            for (int i = 0; i < torneo.ajedrecistas.Count; i++)
                torneo.crosstable.Add(new FilaCrosstable(i, torneo.ajedrecistas[i], torneo.cantidad_rondas));
            
            grid_crosstable.ItemsSource = torneo.crosstable;
            grid_crosstable.Items.Refresh();
        }

        private void irAtras(object sender, RoutedEventArgs e)
        {
            ventana.mostrarSeccionTorneo();
        }

        private void finalizarRegistro(object sender, RoutedEventArgs e)
        {
            Aplicacion.procesarNuevoTorneo(torneo);
            ventana.Close();
        }
    }
}
